﻿(function () {
    app.modals.CreateOrEditWeChatUserModal = function () {

        var _modalManager;
        var _weChatUserService = abp.services.weChat.weChatUser;
        var _$weChatUserInformationForm = null;

        this.init = function (modalManager) {
            _modalManager = modalManager;

            _$weChatUserInformationForm = _modalManager.getModal().find('form[name=WeChatUserInformationsForm]');
            _$weChatUserInformationForm.validate({ ignore: "" });
        };

        this.save = function() {
            if (!_$weChatUserInformationForm.valid()) {
                return;
            }

            var weChatUser = _$weChatUserInformationForm.serializeFormToObject();

            _modalManager.setBusy(true);
            _weChatUserService.createOrUpdateWeChatUser({
                weChatUser: weChatUser
            }).done(function () {
                abp.notify.info(app.localize('SavedSuccessfully'));
                _modalManager.close();
                abp.event.trigger('app.createOrEditWeChatUserModalSaved');
            }).always(function () {
                _modalManager.setBusy(false);
            });
        };
    };
})();